package pta;

/*
1． 为某保险公司设计一个职工管理系统，其中职工类的属性有：职工编号，姓名，性别，团体险业绩，个体险业绩；方法有：
	每个属性对应的set，get方法；
	不带参数的构造方法；
	带参数的构造方法，完成对职工属性的初始化；
	该类实现接口Comparable，完成对职工总业绩的比较。

2． 设计一个类，实现Comparator接口，完成对团体险业绩的比较；

3． 在Main类中，创建一个职工的线性表，分别完成对职工线性表按照总业绩升序排序，按照团体险业绩升序排序。
	注意：不要设计键盘输入职工信息，可根据样例中提供的数据直接创建职工对象；
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

class Employee implements Comparable<Employee> {
	private int emplid;
	private String name;
	private String gender;
	private int groupPerformance;
	private int personFormance;

	// 不带参数的构造方法
	public Employee() {

	}

	// 带参数的构造方法，完成对职工属性的初始化
	public Employee(int emplid, String name, String gender, int groupPerformance, int personFormance) {
		this.emplid = emplid;
		this.name = name;
		this.gender = gender;
		this.groupPerformance = groupPerformance;
		this.personFormance = personFormance;
	}

	// 每个属性对应的set，get方法
	public int getEmplid() {
		return emplid;
	}

	public void setEmplid(int emplid) {
		this.emplid = emplid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public int getGroupformance() {
		return groupPerformance;
	}

	public void setGroupformance(int groupPerformance) {
		this.groupPerformance = groupPerformance;
	}

	public int getPersonformance() {
		return personFormance;
	}

	public void setPersonformance(int personFormanece) {
		this.personFormance = personFormanece;
	}

	@Override
	public int compareTo(Employee other) {
		int ThistotalPerformance = this.groupPerformance + this.personFormance;
		int totalOtherformance = other.groupPerformance + other.personFormance;
		return Integer.compare(ThistotalPerformance, totalOtherformance);
	}
}

//实现Comparator接口，按照团体险业绩比较
class GroupPerformanceComparator implements Comparator<Employee> {
	@Override
	public int compare(Employee e1, Employee e2) {
		return Integer.compare(e1.getGroupformance(), e2.getGroupformance());
	}
}

public class Main1 {

	public static void main(String[] args) {
		// 创建职工的线性表
		List<Employee> employees = new ArrayList<>();
		employees.add(new Employee(1, "职工1", "female", 500, 400));
		employees.add(new Employee(2, "职工2", "female", 400, 600));
		employees.add(new Employee(3, "职工3", "male", 600, 300));
		employees.add(new Employee(4, "职工4", "female", 800, 200));
		employees.add(new Employee(5, "职工5", "male", 500, 700));
		// 按照总业绩升序排序
		Collections.sort(employees);

		// 输出排序后的职工信息
		System.out.println("编号,团险,个险,姓名,性别");
		for (Employee employee : employees) {
			System.out.println(employee.getEmplid() + "," + employee.getGroupformance() + ","
					+ employee.getPersonformance() + "," + employee.getName() + "," + employee.getGender());
		}

		// 按照团体险业绩升序排序
		Collections.sort(employees, new GroupPerformanceComparator());

		// 输出排序后的职工信息
		System.out.println("编号,团险,个险,姓名,性别");
		for (Employee employee : employees) {
			System.out.println(employee.getEmplid() + "," + employee.getGroupformance() + ","
					+ employee.getPersonformance() + "," + employee.getName() + "," + employee.getGender());
		}

	}

}

/*
 * import java.util.ArrayList; import java.util.Collections; import
 * java.util.Comparator; import java.util.List;
 * 
 * // 职工类 class Employee implements Comparable<Employee> { private int id;
 * private String name; private String gender; private int groupPerformance;
 * private int individualPerformance;
 * 
 * // 不带参数的构造方法 public Employee() { }
 * 
 * // 带参数的构造方法 public Employee(int id, String name, String gender, int
 * groupPerformance, int individualPerformance) { this.id = id; this.name =
 * name; this.gender = gender; this.groupPerformance = groupPerformance;
 * this.individualPerformance = individualPerformance; }
 * 
 * // 各属性的set和get方法 public int getId() { return id; }
 * 
 * public void setId(int id) { this.id = id; }
 * 
 * public String getName() { return name; }
 * 
 * public void setName(String name) { this.name = name; }
 * 
 * public String getGender() { return gender; }
 * 
 * public void setGender(String gender) { this.gender = gender; }
 * 
 * public int getGroupPerformance() { return groupPerformance; }
 * 
 * public void setGroupPerformance(int groupPerformance) { this.groupPerformance
 * = groupPerformance; }
 * 
 * public int getIndividualPerformance() { return individualPerformance; }
 * 
 * public void setIndividualPerformance(int individualPerformance) {
 * this.individualPerformance = individualPerformance; }
 * 
 * // 实现接口Comparable，按照总业绩比较
 * 
 * @Override public int compareTo(Employee other) { int thisTotalPerformance =
 * this.groupPerformance + this.individualPerformance; int otherTotalPerformance
 * = other.groupPerformance + other.individualPerformance; return
 * Integer.compare(thisTotalPerformance, otherTotalPerformance); } }
 * 
 * // 实现Comparator接口，按照团体险业绩比较 class GroupPerformanceComparator implements
 * Comparator<Employee> {
 * 
 * @Override public int compare(Employee e1, Employee e2) { return
 * Integer.compare(e1.getGroupPerformance(), e2.getGroupPerformance()); } }
 * 
 * public class Main { public static void main(String[] args) { // 创建职工的线性表
 * List<Employee> employees = new ArrayList<>(); employees.add(new Employee(1,
 * "职工1", "female", 500, 400)); employees.add(new Employee(2, "职工2", "female",
 * 400, 600)); employees.add(new Employee(3, "职工3", "male", 600, 300));
 * employees.add(new Employee(4, "职工4", "female", 800, 200)); employees.add(new
 * Employee(5, "职工5", "male", 500, 700));
 * 
 * // 按照总业绩升序排序 Collections.sort(employees);
 * 
 * // 输出排序后的职工信息 System.out.println("编号,团险,个险,姓名,性别"); for (Employee employee :
 * employees) { System.out.println(employee.getId() + "," +
 * employee.getGroupPerformance() + "," + employee.getIndividualPerformance() +
 * "," + employee.getName() + "," + employee.getGender()); }
 * 
 * // 按照团体险业绩升序排序 Collections.sort(employees, new GroupPerformanceComparator());
 * 
 * // 输出排序后的职工信息 System.out.println("编号,团险,个险,姓名,性别"); for (Employee employee :
 * employees) { System.out.println(employee.getId() + "," +
 * employee.getGroupPerformance() + "," + employee.getIndividualPerformance() +
 * "," + employee.getName() + "," + employee.getGender()); } } }
 */
